/*
 * Heart_0812025View.java
 */

package heart_0812025;

import java.awt.Component;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Vector;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.table.DefaultTableModel;

/**
 * The application's main frame.
 */
public class Heart_0812025View extends FrameView {
    public static FormGame manchoi = new FormGame();
    DefaultTableModel tbm = new DefaultTableModel();
    public final static int SERVERPORT = 1772;
    public final static int CLIENTPORT = 1775;
    public final static int BUFFER_SIZE = 1024;
    public final static String MSG_SERVER_IDENTIFY = "#I am server";
    public final static String MSG_CLIENT_FIND_SERVER = "#are you server ?";

    private static DatagramSocket clientds;
    private static byte[] buffer;
    private static DatagramPacket pkdp;
    public void run() {
        // Init
        try {
            final byte[] request = MSG_CLIENT_FIND_SERVER.getBytes();
            clientds = new DatagramSocket(CLIENTPORT);
            clientds.setSoTimeout(60000);
            buffer = new byte[BUFFER_SIZE];
            pkdp = new DatagramPacket(buffer, BUFFER_SIZE);


            // Broadcast a message to ask who is server ?
            DatagramPacket outpkdp = new DatagramPacket(request, request.length,
                    InetAddress.getByName("192.168.1.255"), SERVERPORT);
            clientds.send(outpkdp);

            while (true) {
                clientds.receive(pkdp);
                String mess = new String(buffer);
                clientds.receive(pkdp);
                String ID = new String(buffer);
                clientds.receive(pkdp);
                String status = new String(buffer);
                // if this package send from an server.
                if (mess.contains(MSG_SERVER_IDENTIFY)) {
                    update(status, ID);
                    //((Looking4aGame)frame.getContentPane()).update(mess.trim());
                    //System.out.printf("SERVER IP: %s\n",pkdp.getAddress().getHostAddress());
                    //System.out.printf("SERVER: %s\n",mess.substring(20));
                }
                buffer = new byte[BUFFER_SIZE];
                pkdp = new DatagramPacket(buffer, BUFFER_SIZE);
            }
        } catch(IOException ex) {

        }
    }
    public Heart_0812025View(SingleFrameApplication app) {
        super(app);
        
        initComponents();
        panel_option.setVisible(false);
        tbm.addColumn("ID");
        tbm.addColumn("Status");

        panel_joingame.setVisible(false);
        
        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = Heart_0812025App.getApplication().getMainFrame();
            aboutBox = new Heart_0812025AboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        Heart_0812025App.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        panel_menu = new javax.swing.JPanel();
        btn_menu_create = new javax.swing.JButton();
        btn_menu_join = new javax.swing.JButton();
        btn_menu_option = new javax.swing.JButton();
        btn_menu_exit = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        panel_create = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        btn_creategame = new javax.swing.JButton();
        btn_create_cancel = new javax.swing.JButton();
        tbx_create_phong = new javax.swing.JTextField();
        tbx_create_status = new javax.swing.JTextField();
        tbx_create_id = new javax.swing.JTextField();
        panel_option = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        tbx_option_ten = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        cbx_option_hinhnen = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        cbx_option_bobai = new javax.swing.JComboBox();
        option_amluong = new javax.swing.JSlider();
        jLabel10 = new javax.swing.JLabel();
        btn_option_save = new javax.swing.JButton();
        btn_option_done = new javax.swing.JButton();
        panel_joingame = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        dsgame = new javax.swing.JTable();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        jPanel2 = new javax.swing.JPanel();

        mainPanel.setMinimumSize(new java.awt.Dimension(525, 325));
        mainPanel.setName("mainPanel"); // NOI18N

        panel_menu.setName("panel_menu"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(heart_0812025.Heart_0812025App.class).getContext().getResourceMap(Heart_0812025View.class);
        btn_menu_create.setIcon(resourceMap.getIcon("btn_menu_create.icon")); // NOI18N
        btn_menu_create.setText(resourceMap.getString("btn_menu_create.text")); // NOI18N
        btn_menu_create.setName("btn_menu_create"); // NOI18N
        btn_menu_create.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btn_menu_createMouseClicked(evt);
            }
        });

        btn_menu_join.setIcon(resourceMap.getIcon("btn_menu_join.icon")); // NOI18N
        btn_menu_join.setText(resourceMap.getString("btn_menu_join.text")); // NOI18N
        btn_menu_join.setName("btn_menu_join"); // NOI18N
        btn_menu_join.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btn_menu_joinMouseClicked(evt);
            }
        });

        btn_menu_option.setIcon(resourceMap.getIcon("btn_menu_option.icon")); // NOI18N
        btn_menu_option.setText(resourceMap.getString("btn_menu_option.text")); // NOI18N
        btn_menu_option.setName("btn_menu_option"); // NOI18N
        btn_menu_option.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btn_menu_optionMouseClicked(evt);
            }
        });

        btn_menu_exit.setIcon(resourceMap.getIcon("btn_menu_exit.icon")); // NOI18N
        btn_menu_exit.setText(resourceMap.getString("btn_menu_exit.text")); // NOI18N
        btn_menu_exit.setName("btn_menu_exit"); // NOI18N
        btn_menu_exit.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btn_menu_exitMouseClicked(evt);
            }
        });

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setForeground(resourceMap.getColor("jLabel1.foreground")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        javax.swing.GroupLayout panel_menuLayout = new javax.swing.GroupLayout(panel_menu);
        panel_menu.setLayout(panel_menuLayout);
        panel_menuLayout.setHorizontalGroup(
            panel_menuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel_menuLayout.createSequentialGroup()
                .addContainerGap(18, Short.MAX_VALUE)
                .addGroup(panel_menuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel_menuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                        .addComponent(btn_menu_exit, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btn_menu_join, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btn_menu_option, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel1))
                    .addComponent(btn_menu_create, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        panel_menuLayout.setVerticalGroup(
            panel_menuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_menuLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_menu_create, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_menu_join, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_menu_option, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_menu_exit, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(36, Short.MAX_VALUE))
        );

        btn_menu_join.getAccessibleContext().setAccessibleName(resourceMap.getString("jButton2.AccessibleContext.accessibleName")); // NOI18N

        panel_create.setName("panel_create"); // NOI18N

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setForeground(resourceMap.getColor("jLabel2.foreground")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        btn_creategame.setText(resourceMap.getString("btn_creategame.text")); // NOI18N
        btn_creategame.setActionCommand(resourceMap.getString("btn_creategame.actionCommand")); // NOI18N
        btn_creategame.setName("btn_creategame"); // NOI18N
        btn_creategame.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btn_creategameMouseClicked(evt);
            }
        });
        btn_creategame.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_creategameActionPerformed(evt);
            }
        });

        btn_create_cancel.setText(resourceMap.getString("btn_create_cancel.text")); // NOI18N
        btn_create_cancel.setName("btn_create_cancel"); // NOI18N
        btn_create_cancel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btn_create_cancelMouseClicked(evt);
            }
        });

        tbx_create_phong.setText(resourceMap.getString("tbx_create_phong.text")); // NOI18N
        tbx_create_phong.setName("tbx_create_phong"); // NOI18N

        tbx_create_status.setText(resourceMap.getString("tbx_create_status.text")); // NOI18N
        tbx_create_status.setName("tbx_create_status"); // NOI18N

        tbx_create_id.setText(resourceMap.getString("tbx_create_id.text")); // NOI18N
        tbx_create_id.setName("tbx_create_id"); // NOI18N

        javax.swing.GroupLayout panel_createLayout = new javax.swing.GroupLayout(panel_create);
        panel_create.setLayout(panel_createLayout);
        panel_createLayout.setHorizontalGroup(
            panel_createLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_createLayout.createSequentialGroup()
                .addGap(74, 74, 74)
                .addComponent(jLabel2)
                .addContainerGap(80, Short.MAX_VALUE))
            .addGroup(panel_createLayout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(panel_createLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panel_createLayout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(18, 18, 18)
                        .addComponent(tbx_create_id, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panel_createLayout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(tbx_create_phong, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panel_createLayout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(18, 18, 18)
                        .addComponent(tbx_create_status, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(64, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel_createLayout.createSequentialGroup()
                .addGap(56, 56, 56)
                .addComponent(btn_creategame)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 84, Short.MAX_VALUE)
                .addComponent(btn_create_cancel)
                .addGap(55, 55, 55))
        );
        panel_createLayout.setVerticalGroup(
            panel_createLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_createLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addGap(33, 33, 33)
                .addGroup(panel_createLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel3)
                    .addComponent(tbx_create_phong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panel_createLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel4)
                    .addComponent(tbx_create_status, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panel_createLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel5)
                    .addComponent(tbx_create_id, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(52, 52, 52)
                .addGroup(panel_createLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_create_cancel)
                    .addComponent(btn_creategame))
                .addContainerGap(62, Short.MAX_VALUE))
        );

        panel_option.setName("panel_option"); // NOI18N
        panel_option.setPreferredSize(new java.awt.Dimension(331, 285));

        jLabel6.setFont(resourceMap.getFont("jLabel6.font")); // NOI18N
        jLabel6.setForeground(resourceMap.getColor("jLabel6.foreground")); // NOI18N
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setFont(resourceMap.getFont("jLabel7.font")); // NOI18N
        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        tbx_option_ten.setText(resourceMap.getString("tbx_option_ten.text")); // NOI18N
        tbx_option_ten.setName("tbx_option_ten"); // NOI18N

        jLabel8.setFont(resourceMap.getFont("jLabel8.font")); // NOI18N
        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        cbx_option_hinhnen.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Backgroud 1", "Backgroud 2", "Backgroud 3", "Backgroud 4" }));
        cbx_option_hinhnen.setName("cbx_option_hinhnen"); // NOI18N

        jLabel9.setFont(resourceMap.getFont("jLabel9.font")); // NOI18N
        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        cbx_option_bobai.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Bộ 1", "Bộ 2", "Bộ 3", "Bộ 4" }));
        cbx_option_bobai.setName("cbx_option_bobai"); // NOI18N

        option_amluong.setName("option_amluong"); // NOI18N

        jLabel10.setFont(resourceMap.getFont("jLabel10.font")); // NOI18N
        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        btn_option_save.setText(resourceMap.getString("btn_option_save.text")); // NOI18N
        btn_option_save.setName("btn_option_save"); // NOI18N

        btn_option_done.setText(resourceMap.getString("btn_option_done.text")); // NOI18N
        btn_option_done.setName("btn_option_done"); // NOI18N

        javax.swing.GroupLayout panel_optionLayout = new javax.swing.GroupLayout(panel_option);
        panel_option.setLayout(panel_optionLayout);
        panel_optionLayout.setHorizontalGroup(
            panel_optionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_optionLayout.createSequentialGroup()
                .addGap(121, 121, 121)
                .addComponent(jLabel6)
                .addContainerGap(125, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(panel_optionLayout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addGroup(panel_optionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btn_option_save)
                    .addGroup(panel_optionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel7)
                        .addComponent(jLabel8)
                        .addComponent(jLabel9)
                        .addComponent(jLabel10)))
                .addGap(18, 18, 18)
                .addGroup(panel_optionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panel_optionLayout.createSequentialGroup()
                        .addGroup(panel_optionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(tbx_option_ten, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                            .addComponent(cbx_option_hinhnen, 0, 132, Short.MAX_VALUE)
                            .addComponent(cbx_option_bobai, 0, 132, Short.MAX_VALUE)
                            .addComponent(option_amluong, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(58, 58, 58))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel_optionLayout.createSequentialGroup()
                        .addComponent(btn_option_done)
                        .addGap(61, 61, 61))))
        );
        panel_optionLayout.setVerticalGroup(
            panel_optionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_optionLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addGap(18, 18, 18)
                .addGroup(panel_optionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel7)
                    .addComponent(tbx_option_ten, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panel_optionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel8)
                    .addComponent(cbx_option_hinhnen, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panel_optionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel9)
                    .addComponent(cbx_option_bobai, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panel_optionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(option_amluong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addGap(18, 18, 18)
                .addGroup(panel_optionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btn_option_save)
                    .addComponent(btn_option_done))
                .addGap(74, 74, 74))
        );

        panel_joingame.setName("panel_joingame"); // NOI18N
        panel_joingame.setPreferredSize(new java.awt.Dimension(331, 285));

        jLabel11.setFont(resourceMap.getFont("jLabel11.font")); // NOI18N
        jLabel11.setForeground(resourceMap.getColor("jLabel11.foreground")); // NOI18N
        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        dsgame.setBackground(resourceMap.getColor("dsgame.background")); // NOI18N
        dsgame.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID", "Status"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        dsgame.setName("dsgame"); // NOI18N
        dsgame.setSelectionBackground(resourceMap.getColor("dsgame.selectionBackground")); // NOI18N
        jScrollPane1.setViewportView(dsgame);
        dsgame.getColumnModel().getColumn(0).setResizable(false);
        dsgame.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("dsgame.columnModel.title0")); // NOI18N
        dsgame.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("dsgame.columnModel.title1")); // NOI18N

        javax.swing.GroupLayout panel_joingameLayout = new javax.swing.GroupLayout(panel_joingame);
        panel_joingame.setLayout(panel_joingameLayout);
        panel_joingameLayout.setHorizontalGroup(
            panel_joingameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel_joingameLayout.createSequentialGroup()
                .addGap(100, 100, 100)
                .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)
                .addGap(92, 92, 92))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel_joingameLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE)
                .addContainerGap())
        );
        panel_joingameLayout.setVerticalGroup(
            panel_joingameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel_joingameLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addComponent(panel_menu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panel_create, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panel_option, javax.swing.GroupLayout.PREFERRED_SIZE, 337, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panel_joingame, javax.swing.GroupLayout.DEFAULT_SIZE, 340, Short.MAX_VALUE))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panel_joingame, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
                    .addComponent(panel_menu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(panel_create, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(panel_option, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE))
                .addGap(30, 30, 30))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(heart_0812025.Heart_0812025App.class).getContext().getActionMap(Heart_0812025View.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 1213, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 1043, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        jPanel2.setName("jPanel2"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
        addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                load(evt);
            }
        });
    }// </editor-fold>//GEN-END:initComponents

    private void load(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_load
        // TODO add your handling code here:
        
    }//GEN-LAST:event_load

    private void btn_create_cancelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_create_cancelMouseClicked
            // TODO add your handling code here:
        tbx_create_phong.setText("");
        tbx_create_status.setText("");
        tbx_create_id.setText("");
    }//GEN-LAST:event_btn_create_cancelMouseClicked

    private void btn_menu_optionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_menu_optionMouseClicked
        // TODO add your handling code here:
        panel_create.setVisible(false);
        panel_joingame.setVisible(false);
        panel_option.setVisible(true);
    }//GEN-LAST:event_btn_menu_optionMouseClicked

    private void btn_menu_createMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_menu_createMouseClicked
        // TODO add your handling code here:
        panel_option.setVisible(false);
        panel_joingame.setVisible(false);
        panel_create.setVisible(true);

    }//GEN-LAST:event_btn_menu_createMouseClicked
    public void update(String Status,String ID)
    {
       Vector Row = new Vector();       
       Row.add(ID);
       Row.add(Status);       
       tbm.addRow(Row);       
       dsgame.setModel(tbm);
       
    }
    private void btn_menu_joinMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_menu_joinMouseClicked
        // TODO add your handling code here:
        panel_option.setVisible(false);
        panel_create.setVisible(false);
        panel_joingame.setVisible(true);
        run();
        //update();
        // load danh sách server, load danh sách phòng

    
    }//GEN-LAST:event_btn_menu_joinMouseClicked

    private void btn_menu_exitMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_menu_exitMouseClicked
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_btn_menu_exitMouseClicked

    private void btn_creategameMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_creategameMouseClicked
        // TODO add your handling code here:
        manchoi.show();
        JFrame mainFrame = Heart_0812025App.getApplication().getMainFrame();
        mainFrame.setVisible(false);
        //Server.main();
        
    }//GEN-LAST:event_btn_creategameMouseClicked

    private void btn_creategameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_creategameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btn_creategameActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_create_cancel;
    private javax.swing.JButton btn_creategame;
    private javax.swing.JButton btn_menu_create;
    private javax.swing.JButton btn_menu_exit;
    private javax.swing.JButton btn_menu_join;
    private javax.swing.JButton btn_menu_option;
    private javax.swing.JButton btn_option_done;
    private javax.swing.JButton btn_option_save;
    private javax.swing.JComboBox cbx_option_bobai;
    private javax.swing.JComboBox cbx_option_hinhnen;
    private javax.swing.JTable dsgame;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JSlider option_amluong;
    private javax.swing.JPanel panel_create;
    private javax.swing.JPanel panel_joingame;
    private javax.swing.JPanel panel_menu;
    private javax.swing.JPanel panel_option;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JTextField tbx_create_id;
    private javax.swing.JTextField tbx_create_phong;
    private javax.swing.JTextField tbx_create_status;
    private javax.swing.JTextField tbx_option_ten;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
}
